#include<bits/stdc++.h>
using namespace std;
const int N = 100010,M = 1000010;
int n,m,L,V;int ans1,ans2;
struct node{
    int d,v,a;
    int st,en;
    bool f;
    int de1,de2;
}car[N];
int p[N],pre[M];
int road[M],use[N],s[N];
bool A,B,C;
bool cmp(node a,node b){
    return a.de2<b.de2||a.de2==b.de2&&a.de1<b.de1;
}

void solveD(){
    ans1=0;ans2=m;
    memset(pre,0,sizeof pre);
    memset(p,0,sizeof p);
    memset(road,0,sizeof road);
    for(int i=1;i<=m;i++){
        scanf("%d",&p[i]);
        pre[p[i]]++;
    }
    for(int i=1;i<=L;i++)pre[i]+=pre[i-1];
    sort(p+1,p+1+m);
    for(int i=1;i<=n;i++){//overspeed road
        if(car[i].a==0){
            if(car[i].v>V){
                car[i].f=1;
                car[i].st=car[i].d;
                car[i].en=L;
            }
        }
        else if(car[i].a>0){//jiasu
            if(car[i].v>V){
                car[i].f=1;
                car[i].st=car[i].d;
                car[i].en=L;
            }
            else{
                int u=(V*V-car[i].v*car[i].v)/(2*car[i].a);
                if(2*car[i].a*u<V*V-car[i].v*car[i].v)u++;
                if(car[i].d+u<=L){
                    car[i].f=1;
                    car[i].st=car[i].d+u;
                    car[i].en=L;
                }
            }
        }else{
            if(car[i].v>V){
                car[i].f=1;
                car[i].st=car[i].d;
                int u=(V*V-car[i].v*car[i].v)/(2*car[i].a);
                car[i].en=min(L,car[i].d+u);

            }
        }

        if(car[i].f){
            if(car[i].st==0)car[i].de1=0;
            else car[i].de1=pre[car[i].st-1];
            car[i].de2=pre[car[i].en];

            if(car[i].de2-car[i].de1>0)ans1++;
            else {
                car[i].f=0;
            }
        }

    }
    printf("%d ",ans1);

    sort(car+1,car+1+n,cmp);
    int point=-0x3f;
    for(int i=1;i<=n;i++){
        if(!car[i].f)continue;
        if(car[i].de1+1>point){
            point=car[i].de2;
            ans2--;
        }
    }

    printf("%d\n",ans2);
    return;
}

void solve(){
    scanf("%d%d%d%d",&n,&m,&L,&V);
    for(int i=1;i<=n;i++){
        scanf("%d%d%d",&car[i].d,&car[i].v,&car[i].a);
        car[i].f=car[i].st=car[i].en=car[i].de1=car[i].de2=0;
        if(car[i].a==0)B=1,C=1;
        if(car[i].a<0)A=1,B=1;
        if(car[i].a>0)A=1,C=1;
    }

    solveD();
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--)solve();

    return 0;
}

